package com.neo.controller;

import com.alibaba.fastjson.JSONObject;
import com.neo.dao.NeoConnect;
import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.seg.common.Term;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@Api("APP登录接口")
public class languageDeal {

    @Autowired
    private NeoConnect neo4jConnect;

    @PostMapping("/sentence")
    @ApiOperation("1.语句处理")
    public List<String> sentenceDeal(@RequestBody String sentence) {
        HanLP.Config.enableDebug();
        List<Term> seg = HanLP.segment(sentence);
        List<String> collect = seg.stream().map(entity -> {
            return entity.toString();
        }).collect(Collectors.toList());
        return collect;
    }

    private static void neo4jConnect() {
    }

    @PostMapping("/cypher")
    @ApiOperation("2.Cypher处理")
    public List<JSONObject> cypherDealing(@RequestBody String cypher) {

        return neo4jConnect.execCypher(cypher);
    }
}
